#ifndef RPC_SERVER_H_
#define RPC_SERVER_H_

#include "base/base.h"

namespace rpc {
class Acceptor;
class Connection;
class EventManager;
class EventManagerPool;

class RpcEventHandle;

class RpcServer {
  public:
    // ev_mgr must be initiatized.
    RpcServer(EventManager* ev_mgr, const std::string& ip, uint16 port);
    ~RpcServer();

    bool Start();

    void SetHandle(RpcEventHandle* h) {
      ev_handle_.reset(h);
    }

    // call back...
    void AddTransaction(Connection* trans);
    void RemoveTransaction(Connection* trans);

    EventManager* getPoller();

  private:
    EventManager* base_poller_;
    const std::string ip_;
    uint16 port_;

    scoped_ptr<RpcEventHandle> ev_handle_;

    scoped_ptr<Acceptor> acceptor_;
    scoped_ptr<EventManagerPool> event_pooler_;

    Mutex conn_mutex_;
    std::map<uint32, Connection*> conn_map_;

    DISALLOW_COPY_AND_ASSIGN(RpcServer);
};
}

#endif
